<template>
  <div>
    ==={{ checkList }}
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="end">
      <el-button type="primary" @click="sub">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </el-row>
  </div>
</template>
<script>
import { getRoles, addAassign } from '@/api/employees'
export default {
  name: '',
  props: {
    roleIds: {
      type: Array,
      default: () => []
    },
    roleid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      roleList: [],
      checkList: [],
      q: {
        size: 1,
        pagesize: 100
      }
    }
  },
  computed: {
  },
  watch: {
    roleIds: {
      handler(newval) {
        this.checkList = newval
      }
    }
  },
  created() {
    this.initRoles()
  },
  methods: {
    async initRoles() {
      try {
        const res = await getRoles(this.q)
        this.roleList = res.data.rows
      } catch (err) {
        console.log(err)
      }
    },
    async sub() {
      try {
        const permIds = this.checkList
        const res = await addAassign({ id: this.roleid, roleIds: permIds })
        console.log(res)
        this.$message.success('分配权限成功')
        this.close()
      } catch (err) {
        console.log(err)
      }
    },
    // 关闭窗口事件
    close() {
      this.$emit('allotclose')
    }
  }
}
</script>
<style lang='less'  scoped>

</style>
